import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:rwini_edit/view/home/logic.dart';

import 'logic.dart';

getdialog(String data, String title) async {
  final homelogic = Get.put(HomeLogic());
  homelogic.isnowFileSave.value = false;
  return await Get.dialog(PopupPage(data: data, title: title));
}

class PopupPage extends StatelessWidget {
  final String data;
  final String title;
  const PopupPage({super.key, required this.data, required this.title});

  @override
  Widget build(BuildContext context) {
    final logic = Get.put(PopupLogic());
    logic.inputctrl.text = data;

    return AlertDialog(
      title: Text(
        "修改:$title",
        style: const TextStyle(color: Color.fromARGB(255, 66, 204, 255)),
      ),
      content: SizedBox(
        width: 800,
        child: TextField(
          maxLines: 10,
          controller: logic.inputctrl,
        ),
      ),
      actions: [
        TextButton(
            onPressed: () {
              var t = logic.inputctrl.text;
              t = t.replaceAll("\n", "\\n");
              logic.inputctrl.text = "";
              Get.back(result: t);
            },
            child: const Text("保存")),
        TextButton(
            onPressed: () {
              Get.back();
            },
            child: const Text("退出")),
      ],
    );
  }
}
